package com.daedalus.intro.ObjektVSstatic;
/*
 Write an application that estimates the value of the mathematical constant e by using

   e = 1 + 1/1! + 1/2! + 1/3! + ... 1/n!
 */

public class KonstatjaCalcE {

    private int faktorial(int a){
        if (a<2) return 1;
        return a*faktorial(a-1);
    }

 /* ndryshe faktoriali me iteracion (cikel)

    private int faktorial(int a){
        int fact = 1;
        for (int i=1; i<= a; i++){
            fact*=i;
        }
        return fact;
    }
 */

    public double constantE(int m){
        double e = 1;
        for (int n=1; n<m; n++){
            e = e + (double) 1/faktorial(n);
        }
        return e;
    }
}
